package com.gestocasa.model;

import java.util.UUID;
import java.util.Vector;

public class Register {

	private int id;
	private UUID internalId;
	private Vector<RegisterValue> values;
	
	public Register(Area a) {
		this((Register)null);
		if(a != null) {
			for(Attribute at : a.getAttributes()) {
				values.add(new RegisterValue(at, null));
			}
		}
	}
	
	public Register(Register register) {
		id = -1;
		internalId = UUID.randomUUID();
		values = new Vector<RegisterValue>();
		
		if(register != null) {
			id = register.getId();
			internalId = UUID.fromString(register.getInternalId().toString());
			
			for(RegisterValue rv : register.getValues()) {
				values.add(new RegisterValue(rv));
			}
		}
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	public UUID getInternalId() {
		return internalId;
	}

	public void setInternalId(String id) {
		this.internalId = UUID.fromString(id);
	}
	
	public void setInternalId(UUID id) {
		this.internalId = id;
	}

	public Vector<RegisterValue> getValues() {
		return values;
	}

	public void setValues(Vector<RegisterValue> values) {
		this.values = values;
	}
	
	public void setAttributeValue(Attribute a, Object value) {
		if(a != null) {
			for(RegisterValue r : values) {
				if(a.equals(r.getAttribute())) {
					r.setCustomValue(value);
					break;
				}
			}
		}
	}
}
